<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ch="http://java.sun.com/jsf/composite/channel"
                xmlns:pa="http://java.sun.com/jsf/composite/paymentMethod"
                xmlns:au="http://java.sun.com/jsf/composite/autocomplete"
                xmlns:poue="http://primefaces.org/ui/extensions">

    <ui:define name="content">

        <h:form id="form">

            <h:panelGrid columns="4" id="gridSelections" styleClass="alignTop">
                <h:panelGrid columns="1"  id="panSpeciality" styleClass="noBorderGrid1">
                    <p:inputText autocomplete="off" id="txtSearch" value="#{doctorSpecialityController.selectText}" style="width: 176px;" placeholder="Specialities" >
                        <f:ajax execute="txtSearch" render="acSpeciality" event="keyup" />
                        <p:ajax  event="keyup" process="@this" update=":#{p:component('scStaff')}  :#{p:component('tblSessionsOfSelectedConsultant')}" listener="#{bookingController.listnerStaffListForSpecilitySelectedText}"/> 
                    </p:inputText>
                    <h:outputScript>
                        $(document.getElementById('form:txtSearch')).keypress(function (event) {
                        var keycode = (event.keyCode ? event.keyCode : event.which);
                        if (keycode == '13') {
                        document.getElementById("form:txtSearch2").focus();
                        return false;
                        }

                        });
                    </h:outputScript>
                    <p:dataTable  scrollable="true" scrollHeight="280"
                                  id="acSpeciality"
                                  selection="#{bookingController.speciality}"
                                  rowKey="#{spe.id}"
                                  value="#{doctorSpecialityController.selectedItems}"  
                                  var="spe" 
                                  selectionMode="single" 
                                  style="height: 300px; width: 200px; padding: 0px; margin: 0px;">
                        <p:ajax  event="rowSelect" process="@this" update=":#{p:component('scStaff')}  
                                 :#{p:component('tblSessionsOfSelectedConsultant')} 
                                 :#{p:component('panelSelectedBookinDetails')} 
                                 :#{p:component('tblBookingsOfSelectedSession')}" 
                                 listener="#{bookingController.listnerStaffListForRowSelectNew}"/> 
                        <p:column style="text-wrap: avoid; text-overflow: clip; white-space: nowrap;" >
                            <h:outputText id="lblSpeName" value="#{spe.name}" ></h:outputText>
                            <p:tooltip for="lblSpeName" value="#{spe.name}"  showDelay="0" hideDelay="0"   rendered="#{sessionController.institutionPreference.applicationInstitution ne 'Ruhuna'}" ></p:tooltip>
                        </p:column>
                    </p:dataTable>
                </h:panelGrid>

                <h:panelGroup id="scStaff" >
                    <p:inputText autocomplete="off" id="txtSearch2" value="#{bookingController.selectTextConsultant}" style="width: 176px;margin-left: 2px;" placeholder="Consultant" >
                        <f:ajax  event="keyup" execute="@this" render=":#{p:component('tblCon')} :#{p:component('panSpeciality')}  :#{p:component('tblSessionsOfSelectedConsultant')}" listener="#{bookingController.listnerStaffRowSelect}"/> 
                    </p:inputText>
                    <h:outputScript>
                        $(document.getElementById('form:txtSearch2')).keypress(function (event) {
                        var keycode = (event.keyCode ? event.keyCode : event.which);
                        if (keycode == '13') {
                        document.getElementById("form:txtSearch3").focus();
                        return false;
                        }

                        });
                    </h:outputScript>
                    <p:dataTable id="tblCon"  var="mys" rowKey="#{mys.id}" value="#{bookingController.consultants}"
                                 selection="#{bookingController.staff}" scrollable="true" scrollHeight="280"
                                 style="height: 300px; width: 200px; padding: 2px; margin: auto;" 
                                 selectionMode="single" >
                        <p:column style="text-wrap: avoid; text-overflow: clip; white-space: nowrap;">
                            <h:outputText id="lblConName" value="#{mys.person.nameWithTitle}" />
                            <p:tooltip for="lblConName" value="#{mys.person.nameWithTitle}" rendered="#{sessionController.institutionPreference.applicationInstitution ne 'Ruhuna'}" 
                                       showDelay="0" hideDelay="0" 
                                       ></p:tooltip>
                        </p:column>
                        <p:ajax  event="rowSelect" 
                                 process="@this" 
                                 update=":#{p:component('tblSessionsOfSelectedConsultant')} 
                                 :#{p:component('panelSelectedBookinDetails')} 
                                 :#{p:component('tblBookingsOfSelectedSession')}"  
                                 listener="#{bookingController.listnerServiceSessionListForRowSelectNew}"/>
                    </p:dataTable>
                </h:panelGroup>

                <h:panelGroup >
                    <p:inputText autocomplete="off" id="txtSearch3" value="#{bookingController.selectTextSession}" style="width: 176px;margin-left: 2px;" placeholder="Session" >
                        <f:ajax  event="keyup" execute="@this" 
                                 render=":#{p:component('tblSessionsOfSelectedConsultant')}" 
                                 listener="#{bookingController.listnerSessionRowSelect}"/> 
                    </p:inputText>
                    <h:outputScript>
                        $(document.getElementById('form:txtSearch3')).keypress(function (event) {
                        var keycode = (event.keyCode ? event.keyCode : event.which);
                        if (keycode == '13') {
                        document.getElementById("form:cmbPs_focus").focus();
                        return false;
                        }

                        });
                    </h:outputScript>
                    <p:dataTable value="#{bookingController.serviceSessions}" rowKey="#{ses.transRowNumber}"
                                 id="tblSessionsOfSelectedConsultant" var="ses"
                                 selectionMode="single" 
                                 selection="#{bookingController.selectedServiceSession}"
                                 scrollable="true" 
                                 scrollHeight="280" rowStyleClass="#{ses.deactivated ? 'redText':''}" styleClass="noBorder" 
                                 style="height: 300px; width: 420px;">

                        <p:ajax event="rowSelect" process="@this tblSessionsOfSelectedConsultant" 
                                update=":#{p:component('tblBookingsOfSelectedSession')} 
                                :#{p:component('lblSessionTotal')} 
                                :#{p:component('tabViewPatientDetails')} 
                                :#{p:component('panelSelectedBookinDetails')}"
                                listener="#{bookingController.listnerBillSessionListForRowSelectNew}" />
                        <p:column style="text-wrap: none;width: 30px!important;text-align: right;"  rendered="false">
                            <h:outputText value="* " rendered="#{ses.deactivated}" />
                            <h:outputText value="#{ses.sessionDate}" >
                                <f:convertDateTime pattern="E"/>
                            </h:outputText>
                        </p:column>
                        <p:column id="colText" headerText="Session" style="text-wrap: none;"  rendered="false">
<!--                            <h:outputText value="* " rendered="#{ses.deactivated}" />
                            <h:outputText value="#{ses.sessionDate}" >
                                <f:convertDateTime pattern="E"/>
                            </h:outputText>
                            <h:outputText value=" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" />-->
                            <h:outputText value="#{ses.sessionDate}" >
                                <f:convertDateTime pattern="MMM/dd/yyyy"/>
                            </h:outputText>
                            <h:outputText value=" &nbsp;&nbsp;" />
                            <h:outputText value="#{ses.startingTime}" >
                                <f:convertDateTime pattern="hh:mm a"/>
                            </h:outputText>
                            <h:outputText value=" &nbsp;&nbsp;" />
                            <h:outputText value="#{ses.totalFee}" >
                                <f:convertNumber pattern="#,##0" ></f:convertNumber>
                            </h:outputText>
                            <h:outputText value=" &nbsp;&nbsp;" />
                            <h:outputText value="#{ses.transDisplayCountWithoutCancelRefund}" style="color: green" >
                                <f:convertNumber pattern="00" ></f:convertNumber>
                            </h:outputText>
                            <h:outputText value="(" />
                            <h:outputText value="#{ses.maxNo}" rendered="#{ses.maxNo ne 0}" >
                                <f:convertNumber pattern="000" ></f:convertNumber>
                            </h:outputText>
                            <h:outputText value=") &nbsp;&nbsp;#" /> 
                            <h:outputText value="#{ses.displayCount+1}" rendered="#{ses.startingNo eq 0}" style="color: red" >
                                <f:convertNumber pattern="00" ></f:convertNumber>
                            </h:outputText>
                            <h:outputText value="#{ses.displayCount+ses.startingNo}" rendered="#{ses.startingNo gt 0}" style="color: red" >
                                <f:convertNumber pattern="00" ></f:convertNumber>
                            </h:outputText>
                            <h:outputText value=" &nbsp;&nbsp;**" />
                            <h:outputText value="#{ses.transCreditBillCount}" >
                                <f:convertNumber pattern="00" ></f:convertNumber>
                            </h:outputText>
                            <h:outputText value="**" />
                            <h:outputText value=" In" rendered="#{ses.arival eq false}" style="color: green;"/>
                            <h:outputText value=" Out" rendered="#{ses.arival eq true}" style="color: red;"/>
                            <h:outputText value=" Leave *" rendered="#{ses.deactivated}"/>
                        </p:column>

                        <p:column headerText="Session" style="text-wrap: none;"  >
                            <h:outputText id="lblSesName" value="#{ses.name}" escape="false"></h:outputText>
                            <h:outputText value=" *Leave*" escape="false" rendered="#{ses.deactivated}"></h:outputText>
                            <p:tooltip for="lblSesName" value="#{ses.name}" ></p:tooltip>
                        </p:column>
                        <p:column headerText="Max" style="width: 20px!important; text-align: center;" >
                            <h:outputText value="#{ses.maxNo}" rendered="#{ses.maxNo ne 0}">
                                <f:convertNumber pattern="00" ></f:convertNumber>
                            </h:outputText>
                        </p:column>

                        <p:column headerText="Booked" style="width: 20px!important; text-align: center;" >
                            <h:outputText value="#{ses.displayCount}">
                                <f:convertNumber pattern="00" ></f:convertNumber>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Date" style="width: 50px!important; text-align: center;" >
                            <h:outputText value="#{ses.sessionDate}">
                                <f:convertDateTime pattern="dd MMM"/>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Time" style="width: 40px!important; text-align: center;" >
                            <h:outputText value="#{ses.startingTime}">
                                <f:convertDateTime pattern="hh:mm"/>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Fee" style="width: 40px!important; text-align: center;" >
                            <h:outputText value="#{ses.totalFee}">
                                <f:convertNumber pattern="#,##0" ></f:convertNumber>
                            </h:outputText>                                                            
                        </p:column>   
                    </p:dataTable>

                </h:panelGroup>

                <h:panelGroup >
                    <p:spacer height="10px" />
                    <p:dataTable id="tblBookingsOfSelectedSession" style="height: 280px; width: 500px;"
                                 value="#{bookingController.billSessions}" var='bs'
                                 selectionMode="single" rowKey="#{bs.id}" styleClass="noBorder" 
                                 rowStyleClass="#{bs.bill.cancelled eq true or bs.bill.refunded eq true ? 'redText':''}"
                                 selection="#{bookingController.selectedBillSession}" scrollable="true" scrollHeight="275">
                        <p:ajax event="rowSelect" process="@this" update=":#{p:component('detail')}" 
                                listener="#{channelBillController.createBillfees}" />
                        <f:facet name="header">
                            <p:outputLabel value="Bookings" ></p:outputLabel>
                        </f:facet>

                        <p:column headerText="No" style="width: 5px!important;">#{bs.serialNo}</p:column>
                        <p:column headerText="Name" style="width: 50px!important;">#{bs.bill.patient.person.nameWithTitle}</p:column>
                        <p:column headerText="Paid" style="width: 30px!important;">
                            <p:outputLabel rendered="#{bs.bill.paidAmount eq 0}" value="Credit" style="color: green;"/>
                            <p:outputLabel rendered="#{bs.bill.paidAmount eq 0 and bs.bill.paymentMethod eq 'OnCall'}" value="-On Call" style="color: green;"/>
                            <p:outputLabel rendered="#{bs.bill.paidAmount eq 0 and bs.bill.paymentMethod eq 'Staff'}" value="-Staff" style="color: green;"/>
                            <p:outputLabel rendered="#{bs.bill.paidAmount ne 0}" value="Paid"/>
                            <p:outputLabel rendered="#{bs.bill.paidAmount ne 0 and bs.bill.paymentMethod eq 'Agent'}" value="-Agent"/>
                            <p:outputLabel rendered="#{bs.bill.paidAmount ne 0 and bs.bill.paymentMethod eq 'OnCall'}" value="-On Call" />
                            <p:outputLabel rendered="#{bs.bill.paidAmount ne 0 and bs.bill.paymentMethod eq 'Staff'}" value="-Staff" />
                        </p:column>
                        <p:column headerText="C/R" style="width: 20px!important;" >
                            <p:outputLabel value="Cancelled" rendered="#{bs.bill.cancelled==true}"/>
                            <p:outputLabel value="Refunded" rendered="#{bs.bill.refunded==true}"/>
                        </p:column>   
                        <p:column headerText="Agent" style="width: 10px!important;">
                            <p:outputLabel value="#{bs.bill.creditCompany.institutionCode}"/>
                            <p:outputLabel value="(#{bs.bill.toStaff.code})" rendered="#{bs.bill.toStaff ne null}"/>
                        </p:column> 
                        <!--                        <p:column headerText="P/A" style="width: 10px!important;">                           
                                                    <p:outputLabel value="Absent"  rendered="#{bs.absent}"/>  
                                                </p:column> -->
                    </p:dataTable>    
                </h:panelGroup>


            </h:panelGrid>


            <h:panelGrid id="gdManageBookings" columns="2" styleClass="alignTop">

                <p:panel id="gpThisBookingDetails" style="min-width: 450px; max-width: 450px; min-height:400px;max-height: 520px;"  >
                    <f:facet name="header" >
                        <p:tabView id="tabViewAgentBookDetails">
                            <p:tab title="Payemnet Details">
                                <h:panelGrid id="pgNewBookingDetail" columns="2"  > 
                                    <p:outputLabel value="Amount" style="width: 200px!important;"/>

                                    <h:panelGroup id="lblSessionTotal">
                                        <p:outputLabel  
                                            value="#{bookingController.selectedServiceSession.originatingSession.totalFfee}"
                                            rendered="#{channelBillController.foriegn}">
                                            <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                        </p:outputLabel>
                                        <p:outputLabel  
                                            value="#{bookingController.selectedServiceSession.originatingSession.totalFee}"
                                            rendered="#{!channelBillController.foriegn}">
                                            <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                        </p:outputLabel>

                                    </h:panelGroup>

                                    <p:outputLabel value="Payment Method"/>
                                    <h:panelGroup >
                                        <p:selectOneMenu  id="cmbPs" value="#{channelBillController.paymentMethod}">  
                                            <f:selectItem itemLabel="Select Payment Method" ></f:selectItem>
                                            <f:selectItems value="#{enumController.paymentMethodsForChannel}"/>                                                               
                                            <f:ajax execute="@this" render="agent agent2 ballance ballance2 agRefLbl agRefTxt creditCardSlc creditCardbnkLbl tblAgentBooks tblAgentBooks2 :#{p:component('lblSessionTotal')} 
                                                    creditCardTxt creditCardRef slipLblBank slipSelBank slipLblDate date staff autoStaff lblCheque chequNo lblBank agentOnCall agentOnCall2 
                                                    lblChequeDate ChequeDate bankSel :#{p:component('lblSessionTotal')} :#{p:component('tblSessionsOfSelectedConsultant')} tabViewAgentBookDetails" event="change" listener="#{bookingController.generateSessionsOnlyIdNew}" />
                                        </p:selectOneMenu>
                                        <h:outputScript>
                                            $(document.getElementById('form:cmbPs_focus')).keypress(function (event) {
                                            var keycode = (event.keyCode ? event.keyCode : event.which);
                                            alert("sdf");
                                            if (keycode == '13') {
                                            document.getElementById("form:txtSearch3").focus();
                                            return false;
                                            }

                                            });
                                        </h:outputScript>
                                    </h:panelGroup>
                                    <h:outputLabel rendered="#{sessionController.institutionPreference.applicationInstitution eq 'Cooperative'}" id="agentOnCall" value="Agent"  style="display: #{channelBillController.paymentMethod eq 'OnCall' ? 'block' : 'none'} ; " />
                                    <p:autoComplete rendered="#{sessionController.institutionPreference.applicationInstitution eq 'Cooperative'}" id="agentOnCall2" forceSelection="true" style="display: #{channelBillController.paymentMethod eq 'OnCall'? 'block' : 'none'} ; "
                                                    value="#{channelBillController.institutionOnCallAgency}"  completeMethod="#{agencyController.completeAgency}" var="ix"
                                                    itemLabel="#{ix.name}" itemValue="#{ix}" styleClass="mediuminput" >
                                        <p:column>#{ix.institutionCode}</p:column>
                                        <p:column>#{ix.name}</p:column>                                
                                    </p:autoComplete>
                                    <p:outputLabel value="Discount Scheme"/>
                                    <p:selectOneMenu   id="cmbPs2" value="#{channelBillController.paymentScheme}">     
                                        <f:selectItem itemLabel="Select Discount Scheme"/>
                                        <f:selectItems value="#{paymentSchemeController.paymentSchemesForChannel}" 
                                                       var="paysch" itemLabel="#{paysch.name}" itemValue="#{paysch}"  />
                                        <p:ajax process="@this" 
                                                update="lblSessionTotal" 
                                                event="change" 
                                                listener="#{channelBillController.changeListener()}"/>
                                    </p:selectOneMenu>

                                    <h:outputLabel/>
                                    <p:selectBooleanCheckbox id="f" value="#{channelBillController.foriegn}" itemLabel="Foriegner">
                                        <f:ajax event="change" execute="@this :#{p:component('tblSessionsOfSelectedConsultant')}" render="lblSessionTotal :#{p:component('tabViewPatientDetails')}"/>
                                    </p:selectBooleanCheckbox>
                                    <h:outputLabel id="agent" value="Agent"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                    <p:autoComplete id="agent2" forceSelection="true" style="display: #{channelBillController.paymentMethod eq 'Agent'? 'block' : 'none'};"
                                                    value="#{channelBillController.institution}"  completeMethod="#{agencyController.completeAgency}" var="ix"
                                                    itemLabel="#{ix.name}" itemValue="#{ix}" styleClass="shortinput2">
                                        <f:ajax  event="itemSelect" execute="@this"  render="ballance ballance2 lblSessionTotal agRefLbl agRefTxt :#{p:component('agRefLbl')} :#{p:component('tblAgentBooks')} :#{p:component('tblAgentBooks2')} pgNewBookingDetail :#{p:component('ballance2')} :#{p:component('ballance6')} :#{p:component('ballance4')}" listener="#{channelBillController.validateAgentBalance()}"/>
                                        <!--<p:ajax event="click" process="@this" update=":#{p:component('agRefLbl')} :#{p:component('tblAgentBooks')} pgNewBookingDetail" />-->
                                        <p:column>#{ix.institutionCode}</p:column>
                                        <p:column>#{ix.name}</p:column>                                
                                    </p:autoComplete> 

                                    <h:outputLabel id="agRefLbl" value="Agent Ref"  style="display: #{channelBillController.paymentMethod eq 'Agent'? 'block' : 'none'} ; "/>
                                    <p:inputText autocomplete="off" id="agRefTxt" value="#{channelBillController.agentRefNo}"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                    <!--                            <p:tooltip for="agRefLbl agent" >
                                                                    <p:dataTable id="tblAgentBooks" value="#{channelBillController.institution.agentReferenceBooks}" var="a">
                                                                        <p:column>
                                                                            <f:facet name="header">
                                                                                <p:outputLabel value="S.R.N." />
                                                                            </f:facet>
                                                                            <p:outputLabel value="#{a.startingReferenceNumber}" >
                                                                                <f:convertNumber pattern="00000" />
                                                                            </p:outputLabel>
                                                                        </p:column>
                                                                        <p:column>
                                                                            <f:facet name="header">
                                                                                <p:outputLabel value="E.R.N." />
                                                                            </f:facet>
                                                                            <p:outputLabel value="#{a.endingReferenceNumber}" >
                                                                                <f:convertNumber pattern="00000" />
                                                                            </p:outputLabel>
                                                                        </p:column>
                                                                    </p:dataTable>
                                                                </p:tooltip>-->
                                    <!--<p:outputLabel />-->
<!--                                    <p:dataTable emptyMessage="No Book" style="display: #{channelBillController.paymentMethod eq 'Agent'? 'block' : 'none'} ; width: 100px!important;" id="tblAgentBooks" value="#{channelBillController.institution.agentReferenceBooks}" var="a">
                                        <p:column>
                                            <f:facet name="header">
                                                <p:outputLabel value="S.R.N." />
                                            </f:facet>
                                            <p:outputLabel value="#{a.startingReferenceNumber}" >
                                                <f:convertNumber pattern="00000" />
                                            </p:outputLabel>
                                        </p:column>
                                    </p:dataTable>
                                    <p:dataTable emptyMessage="No Book" style="display: #{channelBillController.paymentMethod eq 'Agent'? 'block' : 'none'} ;width: 100px!important; " id="tblAgentBooks2" value="#{channelBillController.institution.agentReferenceBooks}" var="a">
                                        <p:column>
                                            <f:facet name="header">
                                                <p:outputLabel value="E.R.N." />
                                            </f:facet>
                                            <p:outputLabel value="#{a.endingReferenceNumber}" >
                                                <f:convertNumber pattern="00000" />
                                            </p:outputLabel>
                                        </p:column>
                                    </p:dataTable>-->

<!--                                    <h:outputLabel id="ballance" value="Credit Limit"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                    <h:outputLabel id="ballance2" value="#{-channelBillController.institution.allowedCredit}"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; ">
                                        <f:convertNumber  pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <h:outputLabel id="ballance5" value="Max Credit Limit"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                    <h:outputLabel id="ballance6" value="#{-channelBillController.institution.maxCreditLimit}"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; ">
                                        <f:convertNumber  pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <h:outputLabel id="ballance3" value="Ballance"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                    <h:outputLabel id="ballance4" value="#{channelBillController.institution.ballance}"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; ">
                                        <f:convertNumber  pattern="#,##0.00"/>
                                    </h:outputLabel>-->

                                    <h:outputLabel id="staff" value="Staff"  style="display: #{channelBillController.paymentMethod eq 'Staff' ? 'block' : 'none'} ; " />
                                    <h:panelGroup id="autoStaff" style="display: #{channelBillController.paymentMethod eq 'Staff' ? 'block' : 'none'} ; ">
                                        <au:completeStaffChannel value="#{channelBillController.toStaff}" />
                                    </h:panelGroup>

                                    <h:outputLabel id="creditCardRef" value="Card Ref. No." style="display: #{channelBillController.paymentMethod ne 'Card' ? 'none' : 'block'} ;"/>
                                    <p:inputText id="creditCardTxt" autocomplete="off"   value="#{channelBillController.paymentMethodData.creditCard.no}" style="display: #{channelBillController.paymentMethod ne 'Card' ? 'none' : 'block'} ;"/>
                                    <h:outputLabel id="creditCardbnkLbl" value="Select Bank" style="display: #{channelBillController.paymentMethod ne 'Card' ? 'none' : 'block'} ;"/>
                                    <p:selectOneMenu id="creditCardSlc" value="#{channelBillController.paymentMethodData.creditCard.institution}" style="display: #{channelBillController.paymentMethod ne 'Card' ? 'none' : 'block'} ;">
                                        <f:selectItem itemLabel="Select Bank"/>
                                        <f:selectItems value="#{institutionController.banks}" var="inst" itemLabel="#{inst.name}" itemValue="#{inst}"/>
                                    </p:selectOneMenu>




                                    <h:outputLabel id="lblCheque" value="Cheque No." style="display: #{channelBillController.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; "/>
                                    <p:inputText autocomplete="off"  value="#{channelBillController.paymentMethodData.cheque.no}" id="chequNo" style="display: #{channelBillController.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " />
                                    <h:outputLabel id="lblBank" value="Select Bank" style="display: #{channelBillController.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; "/>
                                    <p:selectOneMenu  id="bankSel" value="#{channelBillController.paymentMethodData.cheque.institution}" style="display: #{channelBillController.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " >
                                        <f:selectItem itemLabel="Select Bank"/>
                                        <f:selectItems value="#{institutionController.banks}" var="inst" itemLabel="#{inst.name}" itemValue="#{inst}"/>
                                    </p:selectOneMenu>
                        <!--            <p:inputText autocomplete="off"   value="#{channelBillController.paymentMethodData.creditCard.comment}"  id="memo"/>-->

                                    <h:outputLabel id="lblChequeDate" value="Cheque Date" style="display: #{channelBillController.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; "/>
                                    <p:calendar   value="#{channelBillController.paymentMethodData.cheque.date}" pattern="dd MMMM yyyy" id="ChequeDate" style="display: #{channelBillController.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " >                            
                                    </p:calendar>




                                    <h:outputLabel value="Select Bank" id="slipLblBank" style="display: #{channelBillController.paymentMethod ne 'Slip' ? 'none' : 'block'} ;"/>
                                    <p:selectOneMenu id="slipSelBank" value="#{channelBillController.paymentMethodData.slip.institution}" style="display: #{channelBillController.paymentMethod ne 'Slip' ? 'none' : 'block'} ;">
                                        <f:selectItem itemLabel="Select Bank"/>
                                        <f:selectItems value="#{institutionController.banks}" var="inst" itemLabel="#{inst.name}" itemValue="#{inst}"/>
                                    </p:selectOneMenu>
                                    <h:outputLabel value="Slip Date" id="slipLblDate" style="display: #{channelBillController.paymentMethod ne 'Slip' ? 'none' : 'block'} ;"/>
                                    <p:calendar  value="#{channelBillController.paymentMethodData.slip.date}" pattern="dd MMMM yyyy" id="date" style="display: #{channelBillController.paymentMethod ne 'Slip' ? 'none' : 'block'} ;">                            
                                    </p:calendar>


                                </h:panelGrid>
                            </p:tab>
                            <p:tab title="Agent Book" disabled="#{channelBillController.paymentMethod ne 'Agent'}" >
                                <h:panelGrid id="pgNewBookingDetail2" columns="2"  styleClass="noBorder">

                                    <p:dataTable emptyMessage="No Book" style="display: #{channelBillController.paymentMethod eq 'Agent'? 'block' : 'none'} ; width: 100px!important;" id="tblAgentBooks" value="#{channelBillController.institution.agentReferenceBooks}" var="a">
                                        <p:column>
                                            <f:facet name="header">
                                                <p:outputLabel value="S.R.N." />
                                            </f:facet>
                                            <p:outputLabel value="#{a.startingReferenceNumber}" >
                                                <f:convertNumber pattern="00000" />
                                            </p:outputLabel>
                                        </p:column>
                                    </p:dataTable>
                                    <p:dataTable emptyMessage="No Book" style="display: #{channelBillController.paymentMethod eq 'Agent'? 'block' : 'none'} ;width: 100px!important; " id="tblAgentBooks2" value="#{channelBillController.institution.agentReferenceBooks}" var="a">
                                        <p:column>
                                            <f:facet name="header">
                                                <p:outputLabel value="E.R.N." />
                                            </f:facet>
                                            <p:outputLabel value="#{a.endingReferenceNumber}" >
                                                <f:convertNumber pattern="00000" />
                                            </p:outputLabel>
                                        </p:column>
                                    </p:dataTable>
                                    <h:outputLabel id="ballance" value="Credit Limit"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                    <h:outputLabel id="ballance2" value="#{-channelBillController.institution.allowedCredit}"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; ">
                                        <f:convertNumber  pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <h:outputLabel id="ballance5" value="Max Credit Limit"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                    <h:outputLabel id="ballance6" value="#{-channelBillController.institution.maxCreditLimit}"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; ">
                                        <f:convertNumber  pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <h:outputLabel id="ballance3" value="Ballance"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                    <h:outputLabel id="ballance4" value="#{channelBillController.institution.ballance}"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ;">
                                        <f:convertNumber  pattern="#,##0.00"/>
                                    </h:outputLabel>
                                </h:panelGrid>
                            </p:tab>
                        </p:tabView>


                    </f:facet>
                    <p:tabView id="tabViewPatientDetails" activeIndex="#{channelBillController.patientSearchTab}" >
                        <p:ajax event="tabChange"  process="@this" listener="#{channelBillController.onTabChange}" />
                        <p:tab id="tabNewPt" title="New Pateint">
                            <h:panelGrid columns="2">
                                <h:outputLabel value="Title"/>
                                <p:selectOneMenu id="somNewPtTitle" value="#{channelBillController.newPatient.person.title}"  >
                                    <f:selectItem itemLabel="Select Title"/>
                                    <f:selectItems value="#{billController.title}" var="i" itemLabel="#{i.label}" itemValue="#{i}"/>
                                </p:selectOneMenu>
                                <h:outputLabel value="Name"/>
                                <p:inputText autocomplete="off"  id="txtNewPtName" value="#{channelBillController.newPatient.person.name}" style="width: 200px;text-transform:uppercase;">
                                </p:inputText>

                                <h:outputLabel value="Phone"/>
                                <p:inputMask mask="999-9999999" id="txtNewPtPhone" autocomplete="off" maxlength="11" value="#{channelBillController.newPatient.person.phone}">
                                </p:inputMask>
                                <h:outputLabel value="Sex"/>
                                <p:selectOneMenu id="txtNewSex"  value="#{channelBillController.newPatient.person.sex}" style="width: 200px;">
                                    <f:selectItem itemLabel="Select Sex"/>
                                    <f:selectItems value="#{billController.sex}"/>
                                </p:selectOneMenu> 
                                <p:outputLabel value="Area"></p:outputLabel>
                                <p:autoComplete styleClass="mediuminput" widgetVar="np" id="acnp" forceSelection="true" 
                                                value="#{channelBillController.area}" 
                                                completeMethod="#{areaController.completeArea}" 
                                                var="npt" itemLabel="#{npt.name}" 
                                                itemValue="#{npt}" size="30"  style="width: 40px;">
                                </p:autoComplete>
                            </h:panelGrid>
                        </p:tab>
                        <p:tab  id="tabSearchPt" title="Search Pateint">
                            <h:panelGrid columns="1" >
                                <p:selectBooleanCheckbox value="#{patientController.reportKeyWord.additionalDetails}" 
                                                         itemLabel="Serch Only Registed Patient" >
                                    <f:ajax execute="@this" render="acPt" />
                                </p:selectBooleanCheckbox>
                                <p:autoComplete widgetVar="aPt" id="acPt" forceSelection="true" 
                                                value="#{channelBillController.searchPatient}" 
                                                completeMethod="#{patientController.completePatientByNameOrCode}" 
                                                var="apt" itemLabel="#{apt.person.name}" 
                                                itemValue="#{apt}" size="30"  styleClass="mediuminput">
                                    <p:column headerText="Name">
                                        <h:outputLabel value="#{apt.person.nameWithTitle}" />
                                    </p:column>

                                    <p:column headerText="Age">
                                        <h:outputLabel value="#{apt.age}" />
                                    </p:column>
                                    <p:column headerText="Code">
                                        <h:outputLabel value="#{apt.code}" />
                                    </p:column>
                                    <p:column headerText="Sex">
                                        <h:outputLabel value="#{apt.person.sex}" />
                                    </p:column>
                                    <p:column headerText="Address">
                                        <h:outputLabel value="#{apt.person.address}" />
                                    </p:column>
                                    <p:column headerText="Date of Birth">
                                        <h:outputLabel value="#{apt.person.dob}" >
                                            <f:convertDateTime pattern="dd MMMM yyyy"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:ajax event="itemSelect" process="@this" update="panSearch"/>
                                </p:autoComplete>
                                <h:panelGrid id="panSearch" columns="2" >
                                    <h:outputLabel  rendered="#{channelBillController.searchPatient!=null}" value="Name" />
                                    <h:outputLabel rendered="#{channelBillController.searchPatient!=null}" value=": #{channelBillController.searchPatient.person.nameWithTitle}" />
                                    <h:outputLabel  rendered="#{channelBillController.searchPatient!=null}" value="Code" />
                                    <h:outputLabel rendered="#{channelBillController.searchPatient!=null}" value=": #{channelBillController.searchPatient.code}" />
                                    <h:outputLabel  rendered="#{channelBillController.searchPatient!=null}" value="Phone" />
                                    <h:outputLabel rendered="#{channelBillController.searchPatient!=null}" value=": #{channelBillController.searchPatient.person.phone}" />
                                    <h:outputLabel  rendered="#{channelBillController.searchPatient!=null}" value="Sex" />
                                    <h:outputLabel rendered="#{channelBillController.searchPatient!=null}" value=": #{channelBillController.searchPatient.person.sex}" />
                                    <h:outputLabel  rendered="#{channelBillController.searchPatient!=null}" value="Address" />
                                    <h:outputLabel rendered="#{channelBillController.searchPatient!=null}" value=": #{channelBillController.searchPatient.person.address}" />
                                    <h:outputLabel  rendered="#{channelBillController.searchPatient!=null}" value="Age" />
                                    <h:outputLabel rendered="#{channelBillController.searchPatient!=null}" value=": #{channelBillController.searchPatient.age}" />
                                </h:panelGrid> 
                            </h:panelGrid>  
                        </p:tab>
                        <p:tab  id="tabFees" title="Fees" rendered="#{sessionController.institutionPreference.applicationInstitution eq 'Cooperative' and bookingController.selectedServiceSession.originatingSession.forBillType eq 'XrayScan'}" >
                            <p:dataTable value="#{bookingController.selectedServiceSession.originatingSession.itemFees}" var="f" rowStyleClass="#{(f.name.equals('Doctor Fee') or f.name.equals('Hospital Fee')) ? '':'noDisplayRow'}" >
                                <p:column>
                                    <p:outputLabel value="#{f.name}" />
                                </p:column>
                                <p:column>
                                    <p:outputLabel value="#{f.feeType}" />
                                </p:column>
                                <p:column>

                                    <p:inputText value="#{f.ffee}" rendered="#{channelBillController.foriegn}" />
                                    <p:inputText value="#{f.fee}" rendered="#{!channelBillController.foriegn}" />
                                </p:column>
                            </p:dataTable>
                        </p:tab>
                    </p:tabView>
                    <h:panelGrid columns="3" style="min-width: 100%;">


                        <p:commandButton   id="btnAdd" 
                                           value="Add" process=":#{p:component('tabNewPt')} 
                                           :#{p:component('tabSearchPt')} btnAdd 
                                           :#{p:component('pgNewBookingDetail')}" 
                                           update="gpThisBookingDetails" style="float: right;" 
                                           action="#{channelBillController.add}" 
                                           oncomplete="PF('dlgAdd').show();">   
                            <p:confirm header="Confirmation" message="Are you sure?" icon="ui-icon-alert" />
                        </p:commandButton>
                        <p:confirmDialog global="true" showEffect="fade" hideEffect="explode">
                            <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
                            <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
                        </p:confirmDialog>

                        <p:commandButton  action="#{channelBillController.prepareForNewBill()}"  value="New Booking" ajax="false"/>
                    </h:panelGrid>

                    <p:dialog id="dialogChannelAdded" header="Booked" widgetVar="dlgAdd" 
                              modal="true" height="400" width="600" closable="false">
                        <p:commandButton value="New Bill" action="#{channelBillController.prepareForNewBill()}" ajax="false"
                                         ></p:commandButton>

                        <p:commandButton value="Back" action="#" ajax="false" oncomplete="PF('dlgAdd').hide();"
                                         rendered="#{!channelBillController.settleSucessFully}" 
                                         ></p:commandButton>

                        <p:commandButton value="Print" ajax="false" action="#"
                                         disabled="#{channelBillController.printingBill.balance ne 0.0 or !channelBillController.settleSucessFully}">
                            <p:printer target="panelAddedBillPrint" ></p:printer>
                        </p:commandButton>

                        <p:outputLabel value="Total : " />
                        <p:outputLabel value="#{channelBillController.printingBill.netTotal+channelBillController.printingBill.vat}" style="color: red;font-size: x-large;"/>
                        <p:outputLabel value="Agency Balance : "  rendered="#{channelBillController.printingBill.creditCompany ne null}"/>
                        <p:outputLabel value="#{channelBillController.printingBill.creditCompany.ballance}" style="color: red;font-size: x-large;" rendered="#{channelBillController.printingBill.creditCompany ne null}">
                            <f:convertNumber pattern="#,##0.00" />
                        </p:outputLabel>


                        <h:panelGroup id="panelAddedBillPrint"  rendered="#{channelBillController.settleSucessFully}" >
                            <div >
                                <ch:channelReciptA4WithoutHeadings bill="#{channelBillController.billSession.billItem.bill}" dup="true"/>
                            </div>

                        </h:panelGroup>

                        <h:panelGroup  styleClass="noBorder" rendered="#{!channelBillController.settleSucessFully}" >
                            <br/>
                            <br/>
                            <p:outputLabel value="#{channelBillController.errorText}" style="color:#ff0000; font-size: xx-large;" /> 

                        </h:panelGroup>

                    </p:dialog>  

                </p:panel>

                <p:panel id="panelSelectedBookinDetails">
                    <p:tabView id="detail" style="width: 800px!important;height: 450px!important;">
                        <p:tab title="Booking" id="booking" rendered="#{webUserController.hasPrivilege('ChannelBookingBokking') || sessionController.institutionPreference.applicationInstitution ne 'Ruhuna'}">
                            <h:panelGrid columns="2" >

                                <p:panel header="Booking" rendered="#{bookingController.selectedBillSession.bill.paidBill eq null and bookingController.selectedBillSession.bill.balance ne 0.0}">
                                    <div class="ui-message-error ui-widget ui-corner-all">
                                        <span class="ui-message-error-icon"/>
                                        <span class="ui-message-error-detail">
                                            <h:outputText value="NOT PAID YET" ></h:outputText>
                                        </span>
                                    </div>

                                    <h:panelGrid columns="2">
                                        <p:outputLabel value="Name"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.patient.person.nameWithTitle}" rendered="#{bookingController.selectedBillSession.bill.patient.person.nameWithTitle ne null}"/>
                                        <p:outputLabel value="" rendered="#{bookingController.selectedBillSession.bill.patient.person.nameWithTitle eq null}"/>
                                        <p:outputLabel value="Consultant"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.serviceSession.staff.person.nameWithTitle}"/>
                                        <p:outputLabel value="Appo. No"/>
                                        <ui:repeat value="#{bookingController.selectedBillSession.bill.billItems}" var="bis" >
                                            <p:outputLabel value="#{bis.billSession.serialNo}"/>
                                        </ui:repeat>
                                        <p:outputLabel value="Appointment Date">
                                        </p:outputLabel>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.sessionDate}"> 
                                            <f:convertDateTime pattern="dd MMM yyyy" >
                                            </f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel value="Appointment Time">
                                        </p:outputLabel>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.serviceSession.startingTime}"> 
                                            <f:convertDateTime pattern="hh:mm a" ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel value="Tel "/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.patient.person.phone}"/>
                                        <p:outputLabel value="Bill Total"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.netTotal+bookingController.selectedBillSession.bill.vat}" style="color: red;">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </p:outputLabel>
                                        <p:separator ></p:separator>
                                        <p:separator ></p:separator>
                                        <p:outputLabel value="Payment Method"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.paymentMethod}"/>
                                        <p:outputLabel value="Agent" rendered="#{bookingController.selectedBillSession.bill.creditCompany ne null}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.creditCompany.name}" rendered="#{bookingController.selectedBillSession.bill.creditCompany ne null}"/>
                                        <p:outputLabel value="Agent" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.fromInstitution.name}" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="Agent Ref No" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.billItem.agentRefNo}" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="Staff Name" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Staff'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.toStaff.person.nameWithTitle} - (#{bookingController.selectedBillSession.bill.toStaff.code}) " rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Staff'}"/>
                                        <p:outputLabel value="User"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.creater.webUserPerson.nameWithTitle}"/>
                                        <p:outputLabel value="Booked At"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.createdAt}"> 
                                            <f:convertDateTime pattern="dd MMM yyyy - hh:mm a" ></f:convertDateTime>
                                        </p:outputLabel>

                                        <p:outputLabel value="Settled At" rendered="#{bookingController.selectedBillSession.bill.paidBill ne null}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.paidBill.createdAt}" rendered="#{bookingController.selectedBillSession.bill.paidBill ne null}"> 
                                            <f:convertDateTime pattern="dd MMM yyyy - hh:mm a" ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:separator rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}" ></p:separator>
                                        <p:separator rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}" ></p:separator>
                                        <p:outputLabel style="color: red" value="Payment" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}" />
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.cancelledBill.paymentMethod} #{bookingController.selectedBillSession.bill.refundedBill.paymentMethod}" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="Cancel/Refund User" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.cancelledBill.creater.webUserPerson.nameWithTitle} #{bookingController.selectedBillSession.bill.refundedBill.creater.webUserPerson.nameWithTitle}" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="Cancel/Refund At" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.cancelledBill.createdAt}" rendered="#{bookingController.selectedBillSession.bill.cancelled==true }">
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm a"  ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.refundedBill.createdAt}" rendered="#{bookingController.selectedBillSession.bill.refunded==true}">
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm a"  ></f:convertDateTime>
                                        </p:outputLabel> 
                                        <p:outputLabel style="color: red" value="Comment" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}" />
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.cancelledBill.comments} #{bookingController.selectedBillSession.bill.refundedBill.comments}" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}"/>
                                    </h:panelGrid>                            
                                </p:panel>

                                <p:panel header="Booking &amp; Settling" rendered="#{bookingController.selectedBillSession.bill.paidBill eq bookingController.selectedBillSession.bill and bookingController.selectedBillSession.bill.balance eq 0.0}">
                                    <h:panelGrid columns="2">
                                        <p:outputLabel value="Name"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.patient.person.nameWithTitle}" rendered="#{bookingController.selectedBillSession.bill.patient.person.nameWithTitle ne null}"/>
                                        <p:outputLabel value="" rendered="#{bookingController.selectedBillSession.bill.patient.person.nameWithTitle eq null}"/>
                                        <p:outputLabel value="Consultant"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.serviceSession.staff.person.nameWithTitle}"/>
                                        <p:outputLabel value="Appo. No"/>
                                        <ui:repeat value="#{bookingController.selectedBillSession.bill.billItems}" var="bis" >
                                            <p:outputLabel value="#{bis.billSession.serialNo}"/>
                                        </ui:repeat>
                                        <p:outputLabel value="Appointment Date">
                                        </p:outputLabel>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.sessionDate}"> 
                                            <f:convertDateTime pattern="dd MMM yyyy" >
                                            </f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel value="Appointment Time">
                                        </p:outputLabel>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.serviceSession.startingTime}"> 
                                            <f:convertDateTime pattern="hh:mm a" ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel value="Tel "/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.patient.person.phone}"/>
                                        <p:separator ></p:separator>
                                        <p:separator ></p:separator>

                                        <p:outputLabel value="Bill No"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.deptId}" rendered="#{sessionController.institutionPreference.applicationInstitution eq 'Cooperative'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.insId}" rendered="#{sessionController.institutionPreference.applicationInstitution ne 'Cooperative'}"/>
                                        <p:outputLabel value="Bill Total"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.netTotal+bookingController.selectedBillSession.bill.vat}" style="color: red;">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </p:outputLabel>
                                        <p:outputLabel value="Payment"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.paymentMethod}"/>
                                        <p:outputLabel value="Agent" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.creditCompany.name}" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="Agent Ref No" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.billItem.agentRefNo}" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="Staff Name" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Staff'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.toStaff.person.nameWithTitle} - (#{bookingController.selectedBillSession.bill.toStaff.code}) " rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Staff'}"/>
                                        <p:outputLabel value="User"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.creater.webUserPerson.nameWithTitle}"/>
                                        <p:outputLabel value="Billed At"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.createdAt}"> 
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm a" ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:separator rendered="#{bookingController.selectedBillSession.bill.printed==true}" ></p:separator>
                                        <p:separator rendered="#{bookingController.selectedBillSession.bill.printed==true}" ></p:separator>
                                        <!--                                        <p:outputLabel value="Printed User"/>
                                                                                <p:outputLabel value="#{bookingController.selectedBillSession.bill.printedUser.webUserPerson.nameWithTitle}"/>
                                                                                <p:outputLabel value="Printed At"/>
                                                                                <p:outputLabel value="#{bookingController.selectedBillSession.bill.printedAt}"> 
                                                                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm a" ></f:convertDateTime>
                                                                                </p:outputLabel>-->
                                        <p:separator rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}" ></p:separator>
                                        <p:separator rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}" ></p:separator>
                                        <p:outputLabel style="color: red" value="Payment" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}" />
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.cancelledBill.paymentMethod} #{bookingController.selectedBillSession.bill.refundedBill.paymentMethod}" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="Cancel/Refund User" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.cancelledBill.creater.webUserPerson.nameWithTitle} #{bookingController.selectedBillSession.bill.refundedBill.creater.webUserPerson.nameWithTitle}" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="Cancel/Refund At" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.cancelledBill.createdAt}" rendered="#{bookingController.selectedBillSession.bill.cancelled==true }">
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm a"  ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.refundedBill.createdAt}" rendered="#{bookingController.selectedBillSession.bill.refunded==true}">
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm a"  ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel style="color: red" value="Comment" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}" />
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.cancelledBill.comments} #{bookingController.selectedBillSession.bill.refundedBill.comments}" rendered="#{bookingController.selectedBillSession.bill.cancelled==true or bookingController.selectedBillSession.bill.refunded==true}"/>
                                    </h:panelGrid>                            
                                </p:panel>

                                <p:panel header="Booking" rendered="#{(bookingController.selectedBillSession.bill.paidBill ne bookingController.selectedBillSession.bill) and bookingController.selectedBillSession.bill.balance eq 0.0}">
                                    <h:panelGrid columns="2">
                                        <p:outputLabel value="Name"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.patient.person.nameWithTitle}" rendered="#{bookingController.selectedBillSession.bill.patient.person.nameWithTitle ne 'null'}"/>
                                        <p:outputLabel value="" rendered="#{bookingController.selectedBillSession.bill.patient.person.nameWithTitle eq 'null'}"/>
                                        <p:outputLabel value="Consultant"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.serviceSession.staff.person.nameWithTitle}"/>
                                        <p:outputLabel value="Appo. No"/>
                                        <ui:repeat value="#{bookingController.selectedBillSession.bill.billItems}" var="bis" >
                                            <p:outputLabel value="#{bis.billSession.serialNo}"/>
                                        </ui:repeat>
                                        <p:outputLabel value="Appointment Date">
                                        </p:outputLabel>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.sessionDate}"> 
                                            <f:convertDateTime pattern="dd MMM yyyy" >
                                            </f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel value="Appointment Time">
                                        </p:outputLabel>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.serviceSession.startingTime}"> 
                                            <f:convertDateTime pattern="hh:mm a" ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel value="Tel "/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.patient.person.phone}"/>
                                        <p:outputLabel value="Bill Total"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.netTotal+bookingController.selectedBillSession.bill.vat}" style="color: red;">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </p:outputLabel>
                                        <p:separator ></p:separator>
                                        <p:separator ></p:separator>
                                        <p:outputLabel value="Payment"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.paymentMethod}"/>
                                        <p:outputLabel value="Agent" rendered="#{bookingController.selectedBillSession.bill.creditCompany ne null}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.creditCompany.name}" rendered="#{bookingController.selectedBillSession.bill.creditCompany ne null}"/>
                                        <p:outputLabel value="Agent" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.fromInstitution.name}" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="Agent Ref No" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.billItem.agentRefNo}" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="Booking User"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.creater.webUserPerson.nameWithTitle}"/>
                                        <p:outputLabel value="Staff Name" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Staff'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.toStaff.person.nameWithTitle} - (#{bookingController.selectedBillSession.bill.toStaff.code}) " rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Staff'}"/>
                                        <p:outputLabel value="Booked At"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.createdAt}"> 
                                            <f:convertDateTime pattern="dd MMM yyyy - hh:mm a" ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel value="Settled At" rendered="#{bookingController.selectedBillSession.bill.paidBill ne null}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.paidBill.createdAt}" rendered="#{bookingController.selectedBillSession.bill.paidBill ne null}"> 
                                            <f:convertDateTime pattern="dd MMM yyyy - hh:mm a" ></f:convertDateTime>
                                        </p:outputLabel>
                                    </h:panelGrid>                            
                                </p:panel>

                                <p:panel header="Settling" rendered="#{(bookingController.selectedBillSession.bill.paidBill ne bookingController.selectedBillSession.bill) and bookingController.selectedBillSession.bill.balance eq 0.0}">
                                    <h:panelGrid columns="2">
                                        <p:outputLabel value="Bill Id"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.paidBill.deptId}" rendered="#{sessionController.institutionPreference.applicationInstitution eq 'Cooperative'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.paidBill.insId}" rendered="#{sessionController.institutionPreference.applicationInstitution ne 'Cooperative'}"/>
                                        <p:outputLabel value="Cancel Id(Booking)" rendered="#{webUserController.hasPrivilege('Developers')}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.cancelledBill.deptId}" rendered="#{webUserController.hasPrivilege('Developers')}"/>
                                        <p:outputLabel value="Payment Method"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.paidBill.paymentMethod}"/>
                                        <p:outputLabel value="Agent" rendered="#{bookingController.selectedBillSession.bill.paidBill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.paidBill.fromInstitution.name}" 
                                                       rendered="#{bookingController.selectedBillSession.bill.paidBill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="Agent Ref No" rendered="#{bookingController.selectedBillSession.bill.paidBill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.billItem.paidBill.agentRefNo}" rendered="#{bookingController.selectedBillSession.bill.paidBill.paymentMethod eq 'Agent'}"/>
                                        <p:outputLabel value="User"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.paidBill.creater.webUserPerson.nameWithTitle}"/>
                                        <p:outputLabel value="Settled At"/>
                                        <p:outputLabel value="#{bookingController.selectedBillSession.bill.paidBill.createdAt}"> 
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm a" ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:separator rendered="#{bookingController.selectedBillSession.bill.paidBill.cancelled==true or bookingController.selectedBillSession.bill.paidBill.refunded==true}" ></p:separator>
                                        <p:separator rendered="#{bookingController.selectedBillSession.bill.paidBill.cancelled==true or bookingController.selectedBillSession.bill.paidBill.refunded==true}" ></p:separator>
                                        <p:outputLabel style="color: red" value="Payment" rendered="#{bookingController.selectedBillSession.bill.paidBill.cancelled==true or bookingController.selectedBillSession.bill.paidBill.refunded==true}" />
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.paidBill.cancelledBill.paymentMethod} #{bookingController.selectedBillSession.bill.paidBill.refundedBill.paymentMethod}" rendered="#{bookingController.selectedBillSession.bill.paidBill.cancelled==true or bookingController.selectedBillSession.bill.paidBill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="Cancel/Refund User" rendered="#{bookingController.selectedBillSession.bill.paidBill.cancelled==true or bookingController.selectedBillSession.bill.paidBill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.paidBill.cancelledBill.creater.webUserPerson.nameWithTitle} #{bookingController.selectedBillSession.bill.paidBill.refundedBill.creater.webUserPerson.nameWithTitle}" rendered="#{bookingController.selectedBillSession.bill.paidBill.cancelled==true or bookingController.selectedBillSession.bill.paidBill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="Cancel/Refund At" rendered="#{bookingController.selectedBillSession.bill.paidBill.cancelled==true or bookingController.selectedBillSession.bill.paidBill.refunded==true}"/>
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.paidBill.cancelledBill.createdAt}" rendered="#{bookingController.selectedBillSession.bill.paidBill.cancelled==true }">
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm a"  ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.paidBill.refundedBill.createdAt}" rendered="#{bookingController.selectedBillSession.bill.paidBill.refunded==true}">
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm a"  ></f:convertDateTime>
                                        </p:outputLabel>
                                        <p:outputLabel style="color: red" value="Comment" rendered="#{bookingController.selectedBillSession.bill.paidBill.cancelled==true or bookingController.selectedBillSession.bill.paidBill.refunded==true}" />
                                        <p:outputLabel style="color: red" value="#{bookingController.selectedBillSession.bill.paidBill.cancelledBill.comments} #{bookingController.selectedBillSession.bill.paidBill.refundedBill.comments}" rendered="#{bookingController.selectedBillSession.bill.paidBill.cancelled==true or bookingController.selectedBillSession.bill.paidBill.refunded==true}"/>
                                    </h:panelGrid>                            
                                </p:panel>

                            </h:panelGrid>

                        </p:tab>

                        <p:tab title="Reprint" id="rePrint"
                               rendered="#{webUserController.hasPrivilege('ChannelBookingReprint')}">
                            <h:commandButton value="Print" actionListener="#{channelBillController.updatePrintStatus}"
                                             disabled="#{channelBillController.billSession.billItem.bill.balance ne 0.0}">
                                <f:ajax execute="@this" />
                                <p:printer target="panelAddedBillPrintRe" />
                            </h:commandButton>
                            <p:commandButton value="Print" ajax="false" action="#" 
                                             disabled="#{channelBillController.billSession.billItem.bill.balance ne 0.0}">
                                <p:printer target="panelAddedBillPrintRe" ></p:printer>
                            </p:commandButton>
                            <p:commandButton value="Refresh" ajax="false" action="#" >
                            </p:commandButton>

                            <div style="width: 780px!important;height: 330px!important;overflow:scroll!important;" >
                                <h:panelGroup id="panelAddedBillPrintRe"  >
                                    <ch:channelReciptA4WithoutHeadings bill="#{channelBillController.billSession.billItem.bill}" dup="true"/>
                                </h:panelGroup>
                            </div>
                        </p:tab>

                        <p:panel id="panelBillPrint" >

                            <h:panelGroup id="panelAddedBillPrint" styleClass="noBorder">
                                <ch:bill_fees bill="#{channelBillController.billSession.billItem.bill}"/>
                            </h:panelGroup>

                        </p:panel>

                        <p:tab title="Cancel" id="cancel" rendered="#{webUserController.hasPrivilege('ChannelBookingCancel') || sessionController.institutionPreference.applicationInstitution ne 'Ruhuna'}">                                                         
                            #{channelBillController.billSession.bill.billType}

                            <h:panelGroup rendered="#{channelBillController.billSession.billItem.bill.paymentMethod eq 'Agent'}" >
                                <p:outputLabel value="Re-payment Method"/>
                                <p:selectOneMenu  id="cmbCancellPs" value="#{channelBillController.cancelPaymentMethod}">  
                                    <f:selectItem itemLabel="Select Cancel Payment Method" ></f:selectItem>
                                    <f:selectItems value="#{enumController.paymentMethodsForChannelAgentSettle}"/>    
                                    <f:ajax event="change" execute="@this"  render="aaa"/>
                                </p:selectOneMenu>
                            </h:panelGroup>
                            <p:outputLabel id="aaa" value="#{channelBillController.cancelPaymentMethod}"/>



                            <h:panelGroup>
                                <ch:bill_fees bill="#{channelBillController.billSession.billItem.bill}" />
                            </h:panelGroup>
                            <h:inputTextarea value="#{channelBillController.comment}"/>
                            <p:commandButton ajax="false" value="Cancel Agent Bill" 
                                             rendered="#{channelBillController.billSession.bill.billType eq 'ChannelAgent'}"
                                             action="#{channelBillController.cancelAgentPaidBill}"
                                             disabled="#{channelBillController.billSession.bill.refunded==true
                                                         or channelBillController.billSession.bill.cancelled==true}"/>
                            <p:commandButton ajax="false" value="Cancel" 
                                             rendered="#{channelBillController.billSession.bill.billType.parent eq 'ChannelCashFlow' and channelBillController.billSession.bill.billType ne 'ChannelAgent'}"
                                             action="#{channelBillController.cancelCashFlowBill}"
                                             disabled="#{channelBillController.billSession.bill.refunded==true
                                                         or channelBillController.billSession.bill.cancelled==true}" 
                                             onclick="onSubmitButton();"/>
                            <p:commandButton ajax="false" value="Cancel Booking" 
                                             rendered="#{(channelBillController.billSession.bill.billType eq 'ChannelOnCall' or channelBillController.billSession.bill.billType eq 'ChannelStaff')and channelBillController.billSession.bill.paidBill eq null}"
                                             action="#{channelBillController.cancelBookingBill}"
                                             disabled="#{channelBillController.billSession.bill.refunded==true
                                                         or channelBillController.billSession.bill.cancelled==true}" 
                                             onclick="onSubmitButton();"/>
                            <p:commandButton ajax="false" value="Cancel Paid" 
                                             rendered="#{channelBillController.billSession.bill.billType.parent eq 'ChannelCreditFlow' and channelBillController.billSession.bill.billType ne 'ChannelAgent'}"
                                             action="#{channelBillController.cancelCreditPaidBill}"
                                             disabled="#{channelBillController.billSession.bill.refunded==true
                                                         or channelBillController.billSession.bill.cancelled==true
                                                         or channelBillController.billSession.bill.paidAmount eq 0}" 
                                             onclick="onSubmitButton();"/>
                        </p:tab>

                        <p:tab title="Refund" id="refund" rendered="#{webUserController.hasPrivilege('ChannelBookingRefund') || sessionController.institutionPreference.applicationInstitution ne 'Ruhuna'}">                          
                            <h:panelGroup>
                                <h:panelGrid columns="2" rendered="#{channelBillController.billSession.billItem.bill.paymentMethod eq 'Agent'}" >

                                    <p:outputLabel value="Re-payment Method"/>
                                    <p:selectOneMenu  id="cmbRefundPs" value="#{channelBillController.refundPaymentMethod}" >  
                                        <f:selectItem itemLabel="Select Cancel Payment Method" ></f:selectItem>
                                        <f:selectItems value="#{enumController.paymentMethodsForChannelAgentSettle}"/>
                                        <f:ajax event="change" execute="@this"  render="aa"/>
                                    </p:selectOneMenu>
                                    <p:outputLabel id="aa" value="#{channelBillController.refundPaymentMethod}"/>

                                </h:panelGrid>
                                <h:panelGrid columns="2">
                                    <h:outputLabel value="Refundable Total : " style="font-weight: bold;color: red;"/>
                                    <h:outputLabel id="tot" value="#{channelBillController.refundableTotal}" style="font-weight: bold; color: red;">
                                        <f:convertNumber pattern="#,###0.00"  />
                                    </h:outputLabel>
                                </h:panelGrid>
                                <p:dataTable value="#{channelBillController.billSession.bill.billFees}" var="bi">
                                    <p:column headerText="Fee Name">
                                        <p:outputLabel value="#{bi.fee.name}"/>
                                    </p:column>
                                    <p:column headerText="Fee Type">
                                        <p:outputLabel value="#{bi.fee.feeType}"/>
                                    </p:column>
                                    <p:column headerText="Fee Value" styleClass="numberCol">
                                        <p:outputLabel value="#{bi.feeValue}">
                                            <f:convertNumber pattern="#,###0.00"  />
                                        </p:outputLabel> 
                                    </p:column>
                                    <p:column headerText="Vat" styleClass="numberCol">
                                        <p:outputLabel value="#{bi.feeVat}" >
                                            <f:convertNumber pattern="#,###0.00"  />
                                        </p:outputLabel> 
                                    </p:column>
                                    <p:column headerText="Fee Total" styleClass="numberCol">
                                        <p:outputLabel value="#{bi.feeVatPlusValue}" >
                                            <f:convertNumber pattern="#,###0.00"  />
                                        </p:outputLabel> 
                                    </p:column>
                                    <p:column headerText="Return Value">
                                        <p:inputText value="#{bi.tmpChangedValue}" disabled="#{sessionController.institutionPreference.applicationInstitution eq 'Ruhuna'}">
                                            <p:ajax process="@this" update=":#{p:component('tot')}" event="blur" listener="#{channelBillController.calRefundTotal()}"/>
                                            <p:ajax process="@this" update=":#{p:component('tot')} @this" event="blur" listener="#{channelBillController.checkRefundTotal()}"/>
                                        </p:inputText>

                                    </p:column>
                                </p:dataTable>
                            </h:panelGroup>
                            <h:inputTextarea value="#{channelBillController.commentR}"/>

                            <p:commandButton ajax="false" value="Refund Agent Bills" 
                                             rendered="#{channelBillController.billSession.billItem.bill.paymentMethod eq 'Agent'}"
                                             action="#{channelBillController.refundAgentBill}" 
                                             disabled="#{channelBillController.billSession.bill.refunded==true
                                                         or channelBillController.billSession.bill.cancelled==true}"
                                             onclick="onSubmitButton();"/>

                            <p:commandButton ajax="false" value="Refund" 
                                             rendered="#{channelBillController.billSession.bill.billType.parent eq 'ChannelCashFlow' and channelBillController.billSession.billItem.bill.paymentMethod ne 'Agent'}"
                                             action="#{channelBillController.refundCashFlowBill}" 
                                             disabled="#{channelBillController.billSession.bill.refunded==true
                                                         or channelBillController.billSession.bill.cancelled==true}"
                                             onclick="onSubmitButton();"/>

                            <p:commandButton ajax="false" value="Refund Paid" 
                                             rendered="#{channelBillController.billSession.bill.billType.parent eq 'ChannelCreditFlow' }"
                                             action="#{channelBillController.refundCreditPaidBill}" 
                                             disabled="#{channelBillController.billSession.bill.refunded==true
                                                         or channelBillController.billSession.bill.cancelled==true
                                                         or channelBillController.billSession.bill.paidAmount eq 0}"
                                             onclick="onSubmitButton();"/>


                        </p:tab>

                        <p:tab title="Settle" id="settle" rendered="#{webUserController.hasPrivilege('ChannelBookingSettle') || sessionController.institutionPreference.applicationInstitution ne 'Ruhuna'}">
                            <p:panel  id="set">
                                <ch:bill_fees bill="#{channelBillController.billSession.billItem.bill}" />

                                <p:outputLabel value="Payment Method"/>
                                <p:selectOneMenu  id="cmbSettlePs" value="#{channelBillController.settlePaymentMethod}">  
                                    <f:selectItems value="#{enumController.paymentMethodsForChannelSettle}"/>                                                               
                                    <f:ajax execute="@this" render="settleAgent settleAgent2 settleBallance settleBallance2 settleAgRefLbl settleAgRefTxt" event="change" />
                                </p:selectOneMenu>

                                <h:outputLabel id="settleAgent" value="Agent"  style="display: #{channelBillController.settlePaymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                <p:autoComplete id="settleAgent2" forceSelection="true" style="display: #{channelBillController.settlePaymentMethod eq 'Agent'? 'block' : 'none'} ; "
                                                value="#{channelBillController.settleInstitution}"  completeMethod="#{agencyController.completeAgency}" var="ix"
                                                itemLabel="#{ix.name}" itemValue="#{ix}" >
                                    <f:ajax  event="itemSelect" execute="@this"  render="settleBallance settleBallance2 settleAgRefLbl settleAgRefTxt"/>
                                    <p:column>#{ix.institutionCode}</p:column>
                                    <p:column>#{ix.name}</p:column>                                
                                </p:autoComplete> 

                                <h:outputLabel id="settleAgRefLbl" value="Agent Reference No"  style="display: #{channelBillController.settlePaymentMethod eq 'Agent'? 'block' : 'none'} ; "/>
                                <p:inputText autocomplete="off" id="settleAgRefTxt" value="#{channelBillController.settleAgentRefNo}"  style="display: #{channelBillController.settlePaymentMethod eq 'Agent' ? 'block' : 'none'} ; " />

                                <h:outputLabel id="settleBallance" value="Credit Limit"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                <h:outputLabel id="settleBallance2" value="#{channelBillController.institution.allowedCredit}"  style="display: #{channelBillController.settlePaymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                <h:outputLabel id="settleBallance5" value=" Max Credit Limit"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                <h:outputLabel id="settleBallance6" value="#{channelBillController.institution.maxCreditLimit}"  style="display: #{channelBillController.settlePaymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                <h:outputLabel id="settleBallance3" value="Ballance"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                <h:outputLabel id="settleBallance4" value="#{channelBillController.institution.ballance}"  style="display: #{channelBillController.settlePaymentMethod eq 'Agent' ? 'block' : 'none'} ; " />


                                <p:commandButton id="setBtn"  value="Settle Credit"
                                                 process="cmbSettlePs settleAgent2 settleAgRefTxt setBtn"
                                                 update="gpSettlePrint"
                                                 action="#{channelBillController.settleCredit}" 
                                                 disabled="#{channelBillController.billSession.bill.billType.parent ne 'ChannelCreditFlow' 
                                                             or channelBillController.billSession.bill.cancelled==true
                                                             or  channelBillController.billSession.bill.paidAmount ne 0}" 
                                                 oncomplete="PF('dlgSettle').show();"/>



                                <h:panelGroup id="gpSettlePrint" >

                                    <p:dialog id="dialogChannelSettle" header="Booked" widgetVar="dlgSettle" 
                                              modal="true" height="400" width="600" closable="false">
                                        <p:commandButton value="New Bill" action="#{channelBillController.makeNull()}" ajax="false" ></p:commandButton>
                                        <p:commandButton value="Back" action="#" ajax="false" oncomplete="PF('dlgAdd').hide();"
                                                         rendered="#{!channelBillController.settleSucessFully}" />
                                        <p:commandButton value="Print" ajax="false" action="#" disabled="#{channelBillController.billSession.billItem.bill.balance ne 0.0}">
                                            <p:printer target="panelAddedBillPrintSettle" ></p:printer>
                                        </p:commandButton>
                                        <p:outputLabel value="Total : " />
                                        <p:outputLabel value="#{channelBillController.printingBill.netTotal+channelBillController.printingBill.vat}" style="color: red;font-size: x-large;"/>

                                        <h:panelGroup id="panelAddedBillPrintSettle" styleClass="noBorder" rendered="#{channelBillController.settleSucessFully}">
                                            <div>
                                                <h:panelGroup rendered="#{sessionController.institutionPreference.channelBillPaperType eq 'Paper24_2x9_3'}">#{sessionController.institutionPreference}-#{sessionController.institutionPreference.channelBillPaperType}-#{sessionController.institutionPreference.applicationInstitution}
                                                    <ch:channelRecipt_24_2x9_3 bill="#{channelBillController.printingBill}" dup="true"/>                                        
                                                </h:panelGroup>
                                            </div>
                                            <div>
                                                <h:panelGroup rendered="#{sessionController.institutionPreference.channelBillPaperType eq 'FiveFivePaper' and sessionController.institutionPreference.applicationInstitution eq 'Ruhuna'}" >
                                                    <ch:channelRecipt_ruhunu_new bill="#{channelBillController.printingBill}" dup="false" hos="true"/>
                                                    <ch:channelRecipt_ruhunu_new bill="#{channelBillController.printingBill}" dup="false" doc="true"/>
                                                </h:panelGroup>
                                            </div>
                                            <!--                                            <div >
                                                                                            <h:panelGroup rendered="#{sessionController.institutionPreference.channelBillPaperType eq 'FiveFivePaper'}">
                                                                                                <h:panelGroup rendered="#{!sessionController.institutionPreference.pharmacyBillPrabodha}" > 
                                                                                                    <ch:channelRecipt bill="#{channelBillController.billSession.billItem.bill}" dup="false"/>
                                                                                                    <ch:channelRecipt bill="#{channelBillController.billSession.billItem.bill}" dup="false"/>
                                                                                                </h:panelGroup>
                                                                                            </h:panelGroup>
                                                                                        </div>-->
                                            <div >
                                                <h:panelGroup rendered="#{sessionController.institutionPreference.channelBillPaperType eq 'PosPaper'}">
                                                    <h:panelGroup rendered="#{sessionController.institutionPreference.pharmacyBillPrabodha}" > 
                                                        <ch:channelReciptPosDouble bill="#{channelBillController.billSession.billItem.bill}" dup="false"/>
                                                    </h:panelGroup>

                                                    <h:panelGroup rendered="#{!sessionController.institutionPreference.pharmacyBillPrabodha and !(sessionController.institutionPreference.applicationInstitution eq 'Cooperative')}" > 
                                                        <ch:channelReciptPos bill="#{channelBillController.billSession.billItem.bill}" dup="false"/>
                                                    </h:panelGroup>

                                                    <h:panelGroup rendered="#{!sessionController.institutionPreference.pharmacyBillPrabodha and sessionController.institutionPreference.applicationInstitution eq 'Cooperative'}" >
                                                        <ch:channelReciptPos_coop bill="#{channelBillController.billSession.billItem.bill}" dup="false"/>
                                                    </h:panelGroup>

                                                </h:panelGroup>
                                            </div>
                                        </h:panelGroup>
                                        <h:panelGroup  styleClass="noBorder" rendered="#{!channelBillController.settleSucessFully}" >
                                            <br/>
                                            <br/>
                                            <p:outputLabel value="#{channelBillController.errorText}" style="color:#ff0000; font-size: xx-large;" /> 
                                        </h:panelGroup>
                                    </p:dialog>
                                </h:panelGroup>

                            </p:panel>

                        </p:tab>

                        <p:tab title="Change" id="change" rendered="#{webUserController.hasPrivilege('ChannelBookingChange') || sessionController.institutionPreference.applicationInstitution ne 'Ruhuna'}">
                            <h:panelGrid columns="2">
                                <h:outputLabel value="Title"/>
                                <p:selectOneMenu  value="#{bookingController.selectedBillSession.bill.patient.person.title}"  >
                                    <f:selectItem itemLabel="Title" />
                                    <f:selectItems value="#{billController.title}"/>
                                </p:selectOneMenu>
                                <p:outputLabel value="Name"/>
                                <p:inputText autocomplete="off" value="#{bookingController.selectedBillSession.bill.patient.person.name}" />
                                <h:outputLabel value="Phone"/>
                                <p:inputMask mask="999-9999999" autocomplete="off" maxlength="11" value="#{bookingController.selectedBillSession.bill.patient.person.phone}">
                                </p:inputMask>
                                <p:outputLabel value="Current Serial No"/>
                                <ui:repeat value="#{bookingController.selectedBillSession.bill.billItems}" var="bis" >
                                    <p:outputLabel value="#{bis.billSession.serialNo}">                                        
                                    </p:outputLabel>
                                </ui:repeat>
                                <p:outputLabel value="Appo. No"/>
                                <p:inputText autocomplete="off" value="#{bookingController.serealNo}">                                        
                                </p:inputText>
                                <p:outputLabel value="Mark As Absent"/>
                                <p:selectBooleanCheckbox value="#{bookingController.selectedBillSession.absent}" >
                                    <p:ajax process="@this" event="change" listener="#{bookingController.listnerMarkAbsent}" />
                                </p:selectBooleanCheckbox>

                                <p:commandButton ajax="false" value="Update Serial" action="#{bookingController.updateSerial()}" 
                                                 disabled="#{bookingController.selectedBillSession.bill.cancelled==true
                                                             or bookingController.selectedBillSession.bill.refunded==true or !webUserController.hasPrivilege('ChannellingEditSerialNo')}" onclick="onSubmitButton();"/>
                                <p:commandButton ajax="false" value="Update Patient" action="#{bookingController.updatePatient}"
                                                 disabled="#{bookingController.selectedBillSession.bill.cancelled==true
                                                             or bookingController.selectedBillSession.bill.refunded==true or (!webUserController.hasPrivilege('ChannellingEditPatientDetails') and channelBillController.billSession.bill.paidAmount ne 0)}" onclick="onSubmitButton();"/>

                            </h:panelGrid>



                        </p:tab>

                        <p:tab title="Search" rendered="#{webUserController.hasPrivilege('ChannelBookingSearch') || sessionController.institutionPreference.applicationInstitution ne 'Ruhuna'}">
                            <h:panelGrid columns="2">
                                <p:calendar id="calFrom"  value="#{channelSearchController.fromDate}" placeholder="From Date" pattern="dd MMMM yyyy hh:mm:ss a" >   
                                    <f:ajax event="dateSelect" execute="@this" render="bSessionSearch"/>
                                </p:calendar>
                                <p:calendar id="calTo"  value="#{channelSearchController.toDate}" placeholder="To Date" pattern="dd MMMM yyyy hh:mm:ss a" >   
                                    <f:ajax event="dateSelect" execute="@this" render="bSessionSearch"/>
                                </p:calendar>

                                <p:inputText id="txtBsSearch" value="#{channelSearchController.txtSearch}" placeholder="Bill No" >
                                </p:inputText>
                                <p:inputText id="txtBsSearch2" value="#{channelSearchController.txtSearchRef}" placeholder="Agent Ref. No" >
                                </p:inputText>
                                <p:inputMask id="txtBsSearch3" value="#{channelSearchController.txtSearchPhone}" mask="999-9999999" />
                                <h:outputLabel />
                                <p:commandButton id="btnBsSearch" 
                                                 value="Search" action="#{channelSearchController.searchForBillSessions}" 
                                                 process="txtBsSearch txtBsSearch2 txtBsSearch3 calFrom calTo btnBsSearch" 
                                                 update="bSessionSearch"></p:commandButton>
                            </h:panelGrid>

                            <p:dataTable id="bSessionSearch" value="#{channelSearchController.searchedBillSessions}" var="bs"
                                         styleClass="noBorder" style="width: 780px!important;height: 270px!important;overflow:scroll!important;">
                                <p:column>
                                    <p:commandButton value="view" action="#{bookingController.viewBill(bs)}" update=":#{p:component('panelSelectedBookinDetails')}" />
                                </p:column>
                                <p:column headerText="Patient Name" style="text-wrap: avoid; text-overflow: clip; white-space: nowrap;" filterBy="#{bs.bill.patient.person.nameWithTitle}" filterMatchMode="contains">
                                    <p:outputLabel value="#{bs.bill.patient.person.nameWithTitle}" />
                                </p:column>
                                <p:column headerText="Phone" style="text-wrap: avoid; text-overflow: clip; white-space: nowrap;" filterBy="#{bs.bill.patient.person.nameWithTitle}" filterMatchMode="contains">
                                    <p:outputLabel value="#{bs.bill.patient.person.phone}" />
                                </p:column>
                                <p:column headerText="Agent Ref No" filterBy="#{bs.billItem.agentRefNo}" filterMatchMode="contains">
                                    <p:outputLabel value="#{bs.billItem.agentRefNo}"/>
                                </p:column>
                                <p:column headerText="Booking Id" filterBy="#{bs.bill.bookingId}" filterMatchMode="contains">
                                    <p:outputLabel value="#{bs.bill.bookingId}" />
                                </p:column>
                                <p:column headerText="Agent" filterBy="#{bs.bill.fromInstitution.institutionCode}" filterMatchMode="contains">
                                    <p:outputLabel value="#{bs.bill.creditCompany.institutionCode}"/>
                                </p:column> 
                                <p:column headerText="App. No" filterBy="#{bs.serialNo}" filterMatchMode="contains">
                                    <p:outputLabel value="#{bs.serialNo}" />
                                </p:column>
<!--                                <p:column headerText="Sepeciality" filterBy="#{bs.serviceSession.staff.speciality.name}" filterMatchMode="contains">
                                    <p:outputLabel value="#{bs.serviceSession.staff.speciality.name}" />
                                </p:column>-->
                                <p:column headerText="Consultant" style="text-wrap: avoid; text-overflow: clip; white-space: nowrap;" filterBy="#{bs.serviceSession.staff.person.nameWithTitle}" filterMatchMode="contains">
                                    <p:outputLabel value="#{bs.serviceSession.staff.person.nameWithTitle}" />
                                </p:column>
                                <p:column headerText="Session Name" style="text-wrap: avoid; text-overflow: clip; white-space: nowrap;" filterBy="#{bs.serviceSession.name}" filterMatchMode="contains">
                                    <p:outputLabel value="#{bs.serviceSession.name}" />
                                </p:column>


<!--                                <p:column headerText="Paid or Not" filterBy="#{bs.bill.billType}" filterMatchMode="contains">
    <p:outputLabel rendered="#{bs.bill.billType eq 'ChannelCredit'}" value="Credit" style="color: red;"/>
    <p:outputLabel rendered="#{bs.bill.billType eq 'ChannelPaid'}" value="Paid"/>
</p:column>-->
                                <p:column headerText="C/R" filterBy="#{bs.bill.billClass}" filterMatchMode="contains">
                                    <p:outputLabel value="Cancelled" rendered="#{bs.bill.cancelled==true}"/>
                                    <p:outputLabel value="Refunded" rendered="#{bs.bill.refunded==true}"/>
                                </p:column>   


<!--                                <p:column headerText="P/A" filterBy="#{bs.absent}" filterMatchMode="contains">    
   <p:outputLabel value="Absent"  rendered="#{bs.absent}"/>
</p:column> -->
                            </p:dataTable> 
                        </p:tab>

                        <p:tab title="Views" rendered="#{webUserController.hasPrivilege('ChannelBookingViews') || sessionController.institutionPreference.applicationInstitution ne 'Ruhuna'}">
                            <h:panelGrid columns="2">
                                <p:panel header="Selected Session">
                                    <h:panelGrid columns="1">
                                        <p:commandButton value="Nurse View " action="#{bookingController.nurse}"  onclick="onSubmitButton();" >                                       
                                        </p:commandButton>
                                        <p:commandButton value="Doctor View " action="#{bookingController.doctor}" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                        <p:commandButton value="Session View " action="#{bookingController.session}" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                        <p:commandButton value="Phone View " action="#{bookingController.phone}" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                        <p:commandButton value="User View " action="#{bookingController.user}" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                    </h:panelGrid>

                                </p:panel>
                                <p:panel header="Today's">
                                    <h:panelGrid columns="1">
                                        <p:commandButton value="All Patient" action="channel_patient_view_today" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                        <p:commandButton value="All Doctor" action="channel_doctor_view_today" actionListener="#{channelReportController.createTotalDoctor()}" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                        <p:commandButton value="All Doctor(Scan)" action="channel_doctor_view_today" actionListener="#{channelReportController.createTotalDoctorScan()}" ajax="false" onclick="onSubmitButton();" rendered="#{sessionController.institutionPreference.applicationInstitution eq 'Cooperative'}">                                        
                                        </p:commandButton>
                                        <p:commandButton value="Doctor Arraival List" action="channel_doctor_view_today_1" actionListener="#{channelReportController.createDoctorArrival()}" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                        <p:commandButton value="All Absent" action="channel_absent_view_today" actionListener="#{channelReportController.createTodayAbsentList()}" ajax="false" onclick="onSubmitButton();">    
                                            <f:setPropertyActionListener value="#{null}" target="#{channelReportController.date}"/>
                                        </p:commandButton>
                                        <p:commandButton value="All Cancel" action="channel_cancel_view_today" actionListener="#{channelReportController.createTodayCancelList()}" ajax="false" onclick="onSubmitButton();">        
                                            <f:setPropertyActionListener value="#{null}" target="#{channelReportController.date}"/>
                                        </p:commandButton>
                                    </h:panelGrid>                                    
                                </p:panel>
                            </h:panelGrid>

                        </p:tab>

                        <p:tab title="Doctor Payment" rendered="#{webUserController.hasPrivilege('ChannelBookingDocPay') || sessionController.institutionPreference.applicationInstitution ne 'Ruhuna'}">
                            <p:panel header="Selected Session">
                                <h:panelGrid columns="1">
                                    <p:commandButton value="Pay Selected Doctor" action="#{bookingController.paySelectedDoctor}" 
                                                     ajax="false" onclick="onSubmitButton();" />                                        
                                    <p:commandButton value="Go To Channel Shedule"
                                                     rendered="#{webUserController.hasPrivilege('Developers')}"
                                                     action="/channel/channel_shedule" 
                                                     ajax="false" onclick="onSubmitButton();" />                                                                                  
                                </h:panelGrid>
                            </p:panel>
                        </p:tab>
                    </p:tabView>
                </p:panel>
                <p:spacer width="100px"></p:spacer>
                <h:panelGroup></h:panelGroup>


            </h:panelGrid>

        </h:form>


    </ui:define>


</ui:composition>